<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>    
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>订单列表</title>
<link rel="stylesheet" href="<%=basePath %>layui/css/layui.css">
<script src="<%=basePath %>layui/layui.js"></script>
<script src="<%=basePath %>backPage/js/jquery.min.js"></script>
<link rel="stylesheet" href="<%=basePath %>backPage/css/font.css">
<link rel="stylesheet" href="<%=basePath %>backPage/css/soulTable.css" media="all"/>
<style type="text/css">
	/* 设置下拉框的高度与表格单元相同 */
	td .layui-form-select {
	     margin-top: -10px;
	     margin-left: -15px;
	     margin-right: -15px;
	 }
</style>
</head>

<body>
<br/>
<!-- 条件查询 -->
<form class="layui-form" action="" onsubmit="return false;">
  <div class="layui-form-item"  style="margin-left: 110px;">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
      <select name="f_uid" lay-search="" id="serch_f_uid" autocomplete="off">
        <option value=""></option>
      </select>
    </div>
    <label class="layui-form-label">商品名称</label>
    <div class="layui-input-inline">
      <select name="f_pid" lay-search="" id="serch_f_pid" autocomplete="off">
        <option value=""></option>
      </select>
    </div>
    <label class="layui-form-label">订单状态</label>
    <div class="layui-input-inline">
      <select name="status" autocomplete="off">
        <option value=""></option>
        <option value="0">待付款</option>
        <option value="1" selected="selected">待发货</option>
        <option value="2">待收货</option>
        <option value="3">待评价</option>
        <option value="4">已完成</option>
      </select>
    </div>
    <div class="layui-input-inline">
      <button class="layui-btn" lay-submit lay-filter="serchBtn"><i class="layui-icon">&#xe615;</i>搜索</button>
    </div>
  </div>
</form>
<hr>

<table id="demo" lay-filter="test"></table>

<!-- 添加的表单 -->
<form id="A_form" class="layui-form" action="" onsubmit="return false;" style="display:none">
<br>
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
      <select name="f_uid" lay-search="" id="A_f_uid"  lay-verify="required" autocomplete="off">
        <option value=""></option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品名称</label>
    <div class="layui-input-inline">
      <select name="f_pid" lay-search="" id="A_f_pid" lay-filter="A_f_pid_filiter" lay-verify="required" autocomplete="off">
        <option value=""></option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">金额</label>
    <div class="layui-input-inline">
      <input type="text" name="money" id="A_money" readonly="readonly" required  lay-verify="required|decimal" placeholder="请输入金额" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">收获人姓名</label>
    <div class="layui-input-inline">
      <input type="text" name="name" required  lay-verify="required" placeholder="请输入收获人名" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">电话</label>
    <div class="layui-input-inline">
      <input type="text" name="phone" required  lay-verify="required|phone" placeholder="请输入电话号" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item x-city" id="A_start">
	  <div class="layui-form-item">
	    <label class="layui-form-label">省</label>
	    <div class="layui-input-inline">
	        <select name="province" lay-filter="province">
	         <option value="">请选择省</option>
	        </select>
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">市</label>
	    <div class="layui-input-inline">
	        <select name="city" lay-filter="city">
	          <option value="">请选择市</option>
	        </select>
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">县/区</label>
	    <div class="layui-input-inline">
	        <select name="area" lay-filter="area">
	          <option value="">请选择县/区</option>
	        </select>
	    </div>
	  </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">详情地址</label>
    <div class="layui-input-inline">
      <input type="text" name="addressInfo" required  lay-verify="required" placeholder="请输入详细地址" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">单件价格</label>
    <div class="layui-input-inline">
      <input type="text" name="price" id="A_price" readonly="readonly" lay-verify="required|decimal" placeholder="请输入价格" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品数量</label>
    <div class="layui-input-inline">
      <input type="text" name="count" id="A_count" oninput="countBlur()"  lay-verify="required|count" placeholder="请输入商品数量" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品尺寸</label>
    <div class="layui-input-inline">
      <input type="text" name="size" id="A_size" readonly="readonly" lay-verify="required|decimal" placeholder="请输入商品尺寸" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">订单备注</label>
    <div class="layui-input-inline">
      <input type="text" name="mark" placeholder="请输入订单备注" autocomplete="off" class="layui-input">
    </div>
    <div class="layui-form-mid layui-word-aux">
         	选填项
    </div>
  </div>
  
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="addBtn">添加</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

<!-- 修改的表单 -->
<form id="U_form" lay-filter="U_form" class="layui-form" action="" onsubmit="return false;" style="display:none">
<br>
	<input type="hidden" name="id" />
  <div class="layui-form-item">
    <label class="layui-form-label">用户名</label>
    <div class="layui-input-inline">
      <select name="f_uid" lay-search="" disabled="disabled" id="U_f_uid" lay-verify="required" autocomplete="off" class="multitermSet">
        <option value=""></option>
      </select>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品名称</label>
    <div class="layui-input-inline">
    	<input type="text" name="pName" readonly="readonly"  lay-verify="required" autocomplete="off" class="layui-input">
      <!-- <select name="f_pid" lay-search="" disabled="disabled" id="U_f_pid" lay-verify="required" autocomplete="off" class="multitermSet">
        <option value=""></option>
      </select> -->
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">金额</label>
    <div class="layui-input-inline">
      <input type="text" name="money" readonly="readonly" required  lay-verify="required|decimal" placeholder="请输入金额" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
  <!-- <div class="layui-form-item">
    <label class="layui-form-label">订单状态</label>
    <div class="layui-input-inline">
      <select name="status" id="U_status" lay-verify="required" autocomplete="off">
        <option value="0">待付款</option>
        <option value="1">待发货</option>
        <option value="2">待收货</option>
        <option value="3">待评价</option>
        <option value="4">已完成</option>
      </select>
    </div>
  </div> -->
  <div class="layui-form-item">
    <label class="layui-form-label">收获人姓名</label>
    <div class="layui-input-inline">
      <input type="text" name="name" required  lay-verify="required" placeholder="请输入收获人名" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">电话</label>
    <div class="layui-input-inline">
      <input type="text" name="phone" required  lay-verify="required|phone" placeholder="请输入电话号" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item x-city" id="U_start">
	  <div class="layui-form-item">
	    <label class="layui-form-label">省</label>
	    <div class="layui-input-inline">
	        <select name="province" id="provinceClick" lay-verify="required" lay-filter="province">
	         <option value="">请选择省</option>
	        </select>
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">市</label>
	    <div class="layui-input-inline">
	        <select name="city" id="U_city" lay-verify="required" lay-filter="city">
	          <option value="">请选择市</option>
	        </select>
	    </div>
	  </div>
	  <div class="layui-form-item">
	    <label class="layui-form-label">县/区</label>
	    <div class="layui-input-inline">
	        <select name="area" id="U_area" lay-verify="required" lay-filter="area">
	          <option value="">请选择县/区</option>
	        </select>
	    </div>
	  </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">详情地址</label>
    <div class="layui-input-inline">
      <input type="text" name="addressInfo" required  lay-verify="required" placeholder="请输入详细地址" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品总数量</label>
    <div class="layui-input-inline">
      <input type="text" name="count" readonly="readonly" required  lay-verify="required|count" placeholder="请输入商品数量" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">订单备注</label>
    <div class="layui-input-inline">
      <input type="text" name="mark" readonly="readonly" placeholder="请输入订单备注" autocomplete="off" class="layui-input multitermSet">
    </div>
    <div class="layui-form-mid layui-word-aux">
         	
    </div>
  </div>
  
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button class="layui-btn" lay-submit lay-filter="updateBtn">修改</button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>

<!-- 查看订单详情信息 -->
<form id="orderDetails" lay-filter="orderDetails" class="layui-form" action="" onsubmit="return false;" style="display:none">
<br>
	<input type="hidden" name="id" />
  <div class="layui-form-item">
    <label class="layui-form-label">收货人:</label>
    <div class="layui-input-inline">
      <div class="layui-input-inline">
    	<input type="text" name="name" readonly="readonly"  lay-verify="required" autocomplete="off" class="layui-input">
    </div>
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品订单号:</label>
    <div class="layui-input-inline">
    	<input type="text" name="orderId" readonly="readonly"  lay-verify="required" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品名称:</label>
    <div class="layui-input-inline">
    	<input type="text" name="pName" readonly="readonly"  lay-verify="required" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">金额:</label>
    <div class="layui-input-inline">
      <input type="text" name="money" readonly="readonly" required  lay-verify="required|decimal" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">手机号:</label>
    <div class="layui-input-inline">
      <input type="text" name="phone" required  lay-verify="required" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">详情地址:</label>
    <div class="layui-input-inline">
      <input type="text" name="details" required  lay-verify="required" autocomplete="off" class="layui-input">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品总数量:</label>
    <div class="layui-input-inline">
      <input type="text" name="count" readonly="readonly" required  lay-verify="required" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">商品大小:</label>
    <div class="layui-input-inline">
      <input type="text" name="odsSize" readonly="readonly" required  lay-verify="required" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">订单创建时间:</label>
    <div class="layui-input-inline">
      <input type="text" name="createTime" readonly="readonly" autocomplete="off" class="layui-input multitermSet">
    </div>
  </div>
</form>


<script type="text/javascript">
function countBlur(){
	  var count = $("#A_count").val();
	  var price = $("#A_price").val();
	  $("#A_money").val(count*price)
}
</script>
<!-- <button class="layui-btn layui-btn-sm" lay-event="add"><i class="layui-icon">&#xe654;</i>添加</button> -->
<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    
   <%-- <button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="delAll"><i class="layui-icon">&#xe640;</i>批量刪除</button> --%>
	<button class="layui-btn layui-btn-warm layui-btn-sm" lay-event="shippingAll"><i class="iconfont">&#xe6e3;</i>  一键发货</button>
  </div>
</script>
 
<script type="text/html" id="barDemo">
  <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon">&#xe642;</i>编辑</a>
  <a id="shipping" class="layui-btn {{d.status=="1" ? "layui-btn-warm":"layui-btn-disabled"}}  layui-btn-xs" lay-event="shipping"><i class="iconfont">&#xe6e3;</i>  发货</a>
  <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon">&#xe640;</i>删除</a>--%>
  <a class="layui-btn layui-btn-xs" lay-event="selectAll"><i class="layui-icon">&#xe642;</i>查看订单详情</a>
</script>

<script type="text/javascript" src="<%=basePath %>backPage/js/xcity.js"></script>
<script>
layui.use(['form','code'], function(){
    form = layui.form;
    layui.code();
   	$('#A_start').xcity();
    $('#U_start').xcity();
  });
</script>


<script type="text/javascript">
layui.config({
    version: 'v1.5.14' // 插件版本号
}).extend({                         
    soulTable: '{/}https://cdn.jsdelivr.net/npm/layui-soul-table/docs/ext/soulTable.slim'
}).use(['table','layer','form','upload','laydate','code','soulTable'], function(){
	  var table = layui.table;
	  var layer = layui.layer;
	  soulTable = layui.soulTable;
	  var form = layui.form;
	  var $ = layui.$;
	  var upload = layui.upload;
	  var laydate = layui.laydate;
	  var currNow = 1; //声明一个全局变量存储当前页码
	  layui.code();
	  //第一个实例
var myTable =  table.render({
	    elem: '#demo'
	    ,height: 565
	    ,url: '<%=basePath %>back/queryAllOrderInfo' //数据接口
    	,where:{
	    	status:1
	    }
	    ,page: true //开启分页
	    ,id:"showAll"
	    ,limits:[10,50,100]
	    ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
	    ,drag: {toolbar: true} // 可以实现固定列与非固定列之间的转换
	    ,rowDrag: {// 行拖动
	    	numbers: true
	    }
	    ,even: true
	    ,totalRow: true
	    ,overflow: { // 默认所有表格都超出
	           type: 'tips',
	           header: true, // 表头支持 overflow
	           total: true // 合计行支持 overflow
	    }
	    /* ,filter: {
            items:['column','data','condition','editCondition','excel','clearCache'],
            cache: true,
        } */
	    ,done: function(res, curr, count){
	        //console.log(res.data);  //代表我们当前页的数据
	        if(res.data==null){
	        	currNow = curr-1;  //如果当前页面没有数据了，就让页码-1
	        	//我们需要手动再重新刷新数据表格
	        	table.reload('showAll', {
		    			  where: { //设定异步数据接口的额外参数，任意设
		    			  }
		    			  ,page: {
		    			    curr: currNow //获取当前的页码
		    			  }
		    			}); //只重载数据
	        }else{
	        	currNow = curr;
	        }
	        
	      }
	    ,cols: [[ //表头
	    	{type: 'checkbox',}
	      ,{type: 'numbers', title: '序号'}
	      ,{field: 'orderId', title: '订单号', width:110, sort: true}
	      ,{field: 'userName', title: '用户名', width:110,sort: true}
	      ,{field: 'pName', title: '购买商品', width:110, sort: true}
	      ,{field: 'name', title: '收获人名', width:110,sort: true}
	      //,{field: 'status', title: '订单状态', width: 150,sort: true,}//toolbar:'#selectStatus'
	      ,{field: 'phone', title: '手机号', width: 120,sort: true,}
	      ,{field: 'province', title: '省', width: 110,sort: true,}
	      ,{field: 'city', title: '市', width: 110,sort: true,}
	      ,{field: 'area', title: '区', width: 110,sort: true,}
	      ,{field: 'addressInfo', title: '详情地址', width: 150,sort: true,}
	      //,{field: 'price', title: '单件价格', width: 110,sort: true,}
	      ,{field: 'count', title: '商品总数量', width: 80,sort: true,}
	      //,{field: 'size', title: '商品尺寸',hide:true, width: 110,sort: true,}
	      ,{field: 'mark', title: '订单备注', width: 150,sort: true,}
	      ,{field: 'createTime', title: '创建时间',hide:true, width: 130, sort: true}
	      ,{field: 'paymentTime', title: '付款时间',hide:true, width: 130, sort: true}
	      ,{field: 'deliveryTime', title: '发货时间',hide:true, width: 130, sort: true}
	      ,{field: 'finishTimeTime', title: '结束时间',hide:true, width: 130, sort: true}
	      ,{field: 'money', title: '订单金额',fixed: 'right', width:120,sort: true} 
	      ,{
	    	  field: 'status'
	          , title: '订单状态'
	        	,fixed: 'right'
	              , templet: function (d) {
	              	if (d.status == 4) {
	                  	return '<div style="color:#5FB878;" >已完成</div>';
	                }else if(d.status == 0){
	                	return '<div style="color:#FF5722;" >待付款</div>';
	                }else if(d.status == 1){
	                	return '<div style="color:#FFB800;" >待发货</div>';
	                }else if(d.status == 2){
	                	return '<div style="color:#1E9FFF;" >待收货</div>';
	                }else if(d.status == 3){
	                	return '<div style="color:#2F4056;" >待评价</div>';
	                }else{
	                	return '<div style="color:#c2c2c2;" >000000</div>';
	                }

	              }
	              ,  width: 100
	  		}
	      ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:330}
	    ]]
	    ,done: function (res, curr, count) {
	    	soulTable.render(this);//拖拽列
            var tableElem = this.elem.next('.layui-table-view');
            count || tableElem.find('.layui-table-header').css('overflow', 'auto');
            layui.each(tableElem.find('select[name="status"]'), function (index, item) {
                var elem = $(item);
                elem.val(elem.data('state')).parents('div.layui-table-cell').css('overflow', 'visible');
            });
            form.render();//刷新表单
        }
	    
	  });
	  
	  
	//自定义添加的验证规则，自带有phone，decimal
      form.verify({
          decimal:[/^[0-9]+([.]{1}[0-9]+){0,1}$/, '只能为小数或整数'],//验证价格
          number:[/^\d{0,8}$/,'只能为整数长度不过8位'],//验证数值
          age: [/^([1-9][0-9]{0,1}|100)$/, '年龄必须为100以内'],//验证年龄
          count:[/^\+?[1-9][0-9]{0,2}$/, '购买数量不能超过4位数']//购买商品数量的限制
      });
      //设置商品基本信息不能修改提示A_multitermSet
	  $(".multitermSet").click(function () {
		  layer.msg("该数据在该页面不能修改！");
	  })
	  
	//监听提交[搜索]
	  form.on('submit(serchBtn)', function(data){
	    //console.log(data.field);  //可以得到相关的参数值
	    //我们需要带着这些参数，重载一下表格就ok
	    table.reload('showAll', {
		  where: { //设定异步数据接口的额外参数，任意设
			f_uid: data.field.f_uid
		    ,f_pid: data.field.f_pid
		    ,status: data.field.status
		    //…
		  }
		  ,page: {
		    curr: 1 //重新从第 1 页开始
		  }
		}); //只重载数据
	  });
	  
	  //用户
	  $.post("<%=basePath%>back/queryAllUserWitchOrderIndoSelect",{
	  },function(res){
		  for(var i=0; i<res.length; i++){
			  $("#serch_f_uid").append("<option value='"+res[i].id+"'>"+res[i].name+"</option>");
			  $("#A_f_uid").append("<option value='"+res[i].id+"'>"+res[i].name+"</option>");
			  $("#U_f_uid").append("<option value='"+res[i].id+"'>"+res[i].name+"</option>");
			  form.render('select');  //让表单当中的select重新渲染
		  }
	  },'json');
	  //商品
	  $.post("<%=basePath%>back/queryAllProductWitchOrderIndoSelect",{
	  },function(res){
		  for(var i=0; i<res.length; i++){
			  $("#serch_f_pid").append("<option value='"+res[i].name+"'>"+res[i].name+"</option>");
			  /* 
			  $("#A_f_pid").append("<option value='"+res[i].id+"'>"+res[i].name+"</option>");
			  $("#U_f_pid").append("<option value='"+res[i].id+"'>"+res[i].name+"</option>");
			   */
			  form.render('select');  //让表单当中的select重新渲染
		  }
	  },'json');
	  
	  /* $(document).ready(function(){
		  //console.log($("td[0] #T_status option:first").val());
	　　  //$("#T_status option[value='0']").attr("disabled",true);
	  });  */
	  $(function(){
		  console.log($("#T_status option[value='0']"));
	  })
	  
	  
	//当添加时商品名称改变时执行,A_f_pid_filiter下拉框
	  form.on('select(A_f_pid_filiter)', function(data){
          let id = data.elem.value; //当前字段变化的值
          if(id!=null && id != ""){//A_money,A_price,A_count,A_size
        	  //根据对应id搜索商品的信息并加入填框中
        	  $.get("<%=basePath %>back/queryProductByIdWitchOrderInfoInput/"+id,{},function(res){
        		  //$("#A_money").val(res.money);
        		  $("#A_price").val(res.newPrice);
        		  //$("#A_count").val(res.count);
        		  $("#A_size").val(res.size);
        		  $("#A_count").val(1);
        		  //计算总价
        		  $("#A_money").val($("#A_price").val()*1);
        	  });
          }else{
        	  layer.msg("不能为空，请重新选择！");
          }
	  });
	  
	//头工具栏事件
	  table.on('toolbar(test)', function(obj){
		console.log(obj);
	    var checkStatus = table.checkStatus(obj.config.id);
	    switch(obj.event){
	      case 'add':
	        /* var data = checkStatus.data;
	        layer.alert(JSON.stringify(data)); */
	        layer.open({
	        	  type: 1,
	        	  title:"添加页面",
	        	  area: ['900px', '500px'],
	        	  content: $('#A_form') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
	        	});
	        
	      break;
	      case 'delAll':
	    	  var data = checkStatus.data;
	    	  if(data.length > 0){
	    		  layer.confirm('真的删除行这'+data.length+'行么', function(index){
	  	  	        var ids = "";
	  	  	        //通过循环将选中的id，用逗号拼接成一个字符串，例如：1，2，3，
	   	  	        for(var i =0; i < data.length; i++){
	  	  	        	ids += data[i].id+",";
	  	  	        }
	  	  	        
	   	  	   $.get("<%=basePath%>back/queryAllOrderInfoStatusByIds",{ids:ids},function(res){
	   	  		   
	   	  			if(res){
	   	  				layer.msg("有些订单未完成无法删除！");
	   	  			}else{
		   	  			$.post("<%=basePath%>back/delAllOrderInfoByIds",{
		  	  	        	ids:ids
		  	  	        },function(res){
		  	  	        	if(res){
		  	  	        		layer.msg("删除成功");
		  	  	        		layer.closeAll('page');
		  	  	        		table.reload('showAll', {
		  	  		    			  where: { //设定异步数据接口的额外参数，任意设
		  	  		    			  }
		  	  		    			  ,page: {
		  	  		    			    curr: currNow //获取当前的页码
		  	  		    			  }
		  	  		    			}); //只重载数据
		  	  	        	}else{
		  	  	        		layer.msg("删除失败");
		  	  	        		layer.closeAll('page');
		  	  	        	}
		  	  	        },'json');
	   	  				
	   	  			}
	   	  		   
	   	  	   });
	  	  	        
	  	     })
	    	  }else{
	    		  layer.msg("你还未选中要删除的行！");
	    	  }
	      break;
	      case 'shippingAll':
	    	  layer.confirm('要全部进行发货么', function(index){
		 	        $.post("<%=basePath%>back/editOrderInfoStatusAllIsOne",{
		 	        },function(res){
		 	        	if(res){
		 	        		layer.msg("发货成功！");
		 	        		layer.closeAll('page');
		 	        		table.reload('showAll', {
		 		    			  where: { //设定异步数据接口的额外参数，任意设
		 		    			  }
		 		    			  ,page: {
		 		    			    curr: currNow //获取当前的页码
		 		    			  }
		 		    			}); //只重载数据
		 	        	}else{
		 	        		layer.msg("发货失败！");
		 	        		layer.closeAll('page');
		 	        	}
		 	        },'json');
		 	   });
	      break;
	    };
	  });
	  
	  //监听行工具事件
	  table.on('tool(test)', function(obj){
	    var data = obj.data;  //当前行的所有数据
	    console.log(data);
	    if(obj.event === 'del'){
	    	if(data.status != 4){
		    	layer.msg("该订单未完成，无法删除！");
		    }else{
		    	layer.confirm('真的删除行么', function(index){
		 	       /*  obj.del();
		 	        layer.close(index); */
		 	        //点击确定按钮的时候才会进来
		 	        var id = obj.data.id;
		 	        $.post("<%=basePath%>back/delOrderInfoById/"+id,{
		 	        },function(res){
		 	        	if(res){
		 	        		layer.msg("删除成功");
		 	        		layer.closeAll('page');
		 	        		table.reload('showAll', {
		 		    			  where: { //设定异步数据接口的额外参数，任意设
		 		    			  }
		 		    			  ,page: {
		 		    			    curr: currNow //获取当前的页码
		 		    			  }
		 		    			}); //只重载数据
		 	        	}else{
		 	        		layer.msg("删除失败");
		 	        		layer.closeAll('page');
		 	        	}
		 	        },'json');
		 	      });	    	
		    }
	      
	    } else if(obj.event === 'edit'){
	    	if(data.status > 1){
	    		layer.msg("该订单已不能进行修改！");
	    	}else{
		    	 layer.open({
		        	  type: 1,
		        	  title:"修改页面",
		        	  area: ['900px', '500px'],
		        	  content: $('#U_form') //这里content是一个DOM，注意：最好该元素要存放在body最外层，否则可能被其它的相对元素所影响
		        	});
		    	 //回显之前把市与区回显问题解决
		    	 $('#U_start').xcity(''+data.province+'',''+data.city+'',''+data.area+'');
		    	//要给修改的表单回显数据
		    	form.val('U_form', data);
		    	//回显过后进行把多余的订单状态禁用
		    	/* var optionsLength = $("#U_status")[0].options.length;
		    	for(var i = 0; i < optionsLength; i ++){
		    		if(data.status != i){
		    			$("#U_status option[value='"+i+"']").attr("disabled",true);
		    			if(data.status+1 == i){
		    				$("#U_status option[value='"+i+"']").attr("disabled",false);
		    			}
		    		}
		    	} */
			    form.render('select');
	    	}
	    }else if(obj.event == 'shipping'){
	    	//获得本行id
	    	var id = obj.data.id;
	    	//获得本行订单状态
	 	    var status = obj.data.status+1;
	    	if(status == 2){
	    		layer.confirm('进行发货么', function(index){
			 	       /*  obj.del();
			 	        layer.close(index); */
			 	        //点击确定按钮的时候才会进来
			 	        $.post("<%=basePath%>back/editOrderInfoStatusById/"+id+"/"+status,{
			 	        },function(res){
			 	        	if(res){
			 	        		layer.msg("发货成功");
			 	        		layer.closeAll('page');
			 	        		table.reload('showAll', {
			 		    			  where: { //设定异步数据接口的额外参数，任意设
			 		    			  }
			 		    			  ,page: {
			 		    			    curr: currNow //获取当前的页码
			 		    			  }
			 		    			}); //只重载数据
			 	        	}else{
			 	        		layer.msg("发货失败");
			 	        		layer.closeAll('page');
			 	        	}
			 	        },'json');
			 	 });
	    	}else{
	    		layer.msg("该订单不能进行发货！");
	    	}
	    }else if(obj.event == 'selectAll'){
	    	//获得本行id
	    	var id = obj.data.id;
	    	//获得本行订单状态
	 	    var orderId = obj.data.orderId;
	 	   	$.ajax({
				url:"<%=basePath%>back/selectOrderDetailsAll/"+orderId,
				type:"post",
				dataType:"json",
				success:function(data){	
			 	    form.val('orderDetails', data);
				},
				error:function(){
					
				}
		   })
	 	   layer.open({
				type:1,
				title:'你正在查看订单号为【'+obj.data.orderId+'】的商品信息',
				content:$('#orderDetails'),
				area:['600px','500px']
			});
	    }
	  });
	  
	  
	  
	  //监听提交[添加按钮]
	  form.on('submit(addBtn)', function(data){
	    //console.log(data);  //可以得到添加表单中文本框的值
	    //我们 需要发送一个请求，带上我们的参数。
	    $.post("<%=basePath%>back/addOrderInfo",{
	    	f_uid:data.field.f_uid,
	    	f_pid:data.field.f_pid,
	    	money:data.field.money,
	    	name:data.field.name,
	    	phone:data.field.phone,
	    	province:data.field.province,
	    	city:data.field.city,
	    	area:data.field.area,
	    	addressInfo:data.field.addressInfo,
	    	price:data.field.price,
	    	count:data.field.count,
	    	size:data.field.size,
	    	mark:data.field.mark,
	    },function(res){
	    	if(res){
	    		layer.close(layer.index);
	    		layer.msg("添加成功");
	    		layer.closeAll('page');
	    		table.reload('showAll', {
	    			  where: { //设定异步数据接口的额外参数，任意设
	    			  }
	    			  ,page: {
	    			    curr: 1 //重新从第 1 页开始
	    			  }
	    			}); //只重载数据
	    		//将表单中的数据进行清空【js的reset方法】
	    		$("#A_form")[0].reset();
	    	}else{
	    		layer.close(layer.index);
	    		layer.msg("添加失败");
	    		layer.closeAll('page');
	    		$("#A_form")[0].reset();
	    	}
	    },'json');
	    
	    
	  });
	  //监听提交[修改按钮]
	  form.on('submit(updateBtn)', function(data){
	    //console.log(data);  //可以得到添加表单中文本框的值
	    //我们 需要发送一个请求，带上我们的参数。
	    $.post("<%=basePath%>back/editOrderInfoById",{
	    	id:data.field.id,
	    	name:data.field.name,
	    	phone:data.field.phone,
	    	province:data.field.province,
	    	city:data.field.city,
	    	area:data.field.area,
	    	addressInfo:data.field.addressInfo,
	    },function(res){
	    	if(res){
	    		layer.close(layer.index);
	    		layer.msg("修改成功");
	    		layer.closeAll('page');
	    		table.reload('showAll', {
	    			  where: { //设定异步数据接口的额外参数，任意设
	    			  }
	    			  ,page: {
	    			    curr: currNow //重新从第 1 页开始
	    			  }
	    			}); //只重载数据
	    		//将表单中的数据进行清空【js的reset方法】
	    		$("#U_form")[0].reset();
	    	}else{
	    		layer.close(layer.index);
	    		layer.msg("修改失败");
	    		layer.closeAll('page');
	    		$("#U_form")[0].reset();
	    	}
	    	
	    },'json');
	    
	    
	  });
	  
	  
	  
});


</script>
</body>
</html>